package StructuralPattern.Proxy.StaticForceProxy;

/**
 * @Classname : ConcreteGamePlayer
 * @Description : 具体角色
 * @Author : chentianyu
 * @Date 2023/2/11 23:19
 */


public class ConcreteGamePlayer implements GamePlayer{

    private String user;
    private GamePlayer proxy;

    public ConcreteGamePlayer(String user) {
        this.user = user;
    }

    @Override
    public GamePlayer getProxy() {
        this.proxy = new GamePlayerProxy(this);
        return this.proxy;
    }

    // 校验是否代理类访问
    private boolean isProxy() {
        return this.proxy != null;
    }

    @Override
    public void login() {
        if (this.isProxy()) {
            System.out.println("玩家 " + this.user + " 登录成功！");
        } else {
            System.out.println("请使用指定的代理角色访问");
        }
    }

    @Override
    public void killBoss() {
        if (this.isProxy()) {
            System.out.println("玩家 " + this.user + " 在打怪！");
        } else {
            System.out.println("请使用指定的代理角色访问");
        }
    }

    @Override
    public void upgrade() {
        if (this.isProxy()) {
            System.out.println("玩家 " + this.user + " 又升了一级！");
        } else {
            System.out.println("请使用指定的代理角色访问");
        }
    }
}
